package cn.ondraw.ragflow.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import cn.ondraw.common.core.domain.R;
import cn.ondraw.ragflow.pojo.request.GetDialogRequest;
import cn.ondraw.ragflow.pojo.request.ListDialogsRequest;
import cn.ondraw.ragflow.pojo.request.RmDialogRequest;
import cn.ondraw.ragflow.pojo.request.SetDialogRequest;
import cn.ondraw.ragflow.service.RagFlowDialogService;
import org.springframework.web.bind.annotation.*;

/**
 * 对话框控制器
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/v1/dialog")
public class RagFlowDialogController {
    private final RagFlowDialogService ragFlowDialogService;

    /**
     * 设置对话框接口
     *
     * @param request 设置对话框的请求对象
     * @return 通用响应对象，包含设置对话框的结果
     */
    @PostMapping("/set")
    public R<Object> setDialog(@RequestBody SetDialogRequest request) {
        try {
            return R.ok(ragFlowDialogService.setDialog(request));
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }

    /**
     * 获取对话框接口
     *
     * @param request 获取对话框的请求对象
     * @return 通用响应对象，包含获取对话框的结果
     */
    @GetMapping("/get")
    public R<Object> getDialog(@ModelAttribute GetDialogRequest request) {
        try {
            return R.ok(ragFlowDialogService.getDialog(request));
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }

    /**
     * 列出对话框接口
     *
     * @param request 列出对话框的请求对象
     * @return 通用响应对象，包含列出对话框的结果
     */
    @GetMapping("/list")
    public R<Object> listDialogs(@ModelAttribute ListDialogsRequest request) {
        try {
            return R.ok(ragFlowDialogService.listDialogs(request));
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }

    /**
     * 删除对话框接口
     *
     * @param request 删除对话框的请求对象
     * @return 通用响应对象，包含删除对话框的结果
     */
    @PostMapping("/rm")
    public R<Object> rmDialogs(@RequestBody RmDialogRequest request) {
        try {
            return R.ok(ragFlowDialogService.rmDialogs(request));
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
    }
}
